<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>展开运算符</title>
</head>
<body>
    <script type="text/javascript">
        let arr1 = [1, 3, 5, 7, 9]
        let arr2 = [2, 4, 6, 8, 10]
        // console.log(...arr1)            //1 3 5 7 9

        let arr3 = [...arr1, ...arr2]
        // console.log(...arr3)        // 1 3 5 7 9 2 4 6 8 10

        function sum(...numbers) {
            // console.log(numbers);
            return numbers.reduce((pre, cur)=>{
                return pre + cur;
            })
        }

        // console.log(sum(1, 2, 3, 4, 5))

        let person = {name: 'zs', age: 18}
        // console.log(...person); 报错，展开运算符不能展开对象

        let person2 = {...person}
        person2.name = '李四'
        console.log(person2);       // {name: '李四', age: 18}
        console.log(person);        // {name: 'zs', age: 18}

        let person3 = {...person, name: 'jack'}     // 修改某个属性的值
        console.log(person3);       // {name: 'jack', age: 18}

    </script>
</body>
</html>